package edu.iscas.xcheck.analysis.controller;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import edu.iscas.xcheck.analysis.handler.AnalysisRunner;
import edu.iscas.xcheck.analysis.model.AnalysisConfig;
import edu.iscas.xcheck.analysis.model.AnalysisInfo;
import edu.iscas.xcheck.analysis.model.AnalysisInfo.AnalysisStatus;

@RestController
public class AnalysisController {
	
	private static ExecutorService analysisPool = Executors.newCachedThreadPool();
	
	private static final Logger LOG = LoggerFactory.getLogger(AnalysisController.class);
	
	@RequestMapping(value = "/Analysis", method = RequestMethod.POST)
	public AnalysisInfo doAnalysis(@RequestBody AnalysisConfig analysisConfig ){
		
		LOG.info(analysisConfig.toString());
		AnalysisRunner analysisRunner = new AnalysisRunner(analysisConfig);
		Future result = analysisPool.submit(analysisRunner); 
		return new AnalysisInfo(analysisConfig.getTestCaseId(), AnalysisStatus.CREATED);
	}

}
